package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 根据分类的父id查询对应的分类集合
 * @author: YHL
 * @time: 2021/2/21 20:49
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
     private CategoryService categoryService;
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>>queryCategoryByParent(@RequestParam("pid")Long pid){

//        ok简化了状态码  ok时状态就是200
        return ResponseEntity.ok(this.categoryService.queryCategoryByParent(pid));
    }


    /**
     * 根据分类id查询对应的分类对象
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryCategoryById(@PathVariable("id")Long id){

        return ResponseEntity.ok(this.categoryService.queryCategoryById(id));
    }


    /**
     * 根据分类的id集合查询对应的分类集合
     * @param ids
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> listCategoryByIds(@RequestParam("ids")List<Long> ids){

        return ResponseEntity.ok(this.categoryService.listCategoryByIds(ids));
    }

    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>>listCategoryByBrand(@RequestParam("id")Long bid){

        return ResponseEntity.ok(this.categoryService.listCategoryByBrand(bid));
    }


}
